//
// Created on 2024/4/24.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".

#ifndef RONGIMLIBTESTDEMO_RCIMNAPITRANSFORMER_H
#define RONGIMLIBTESTDEMO_RCIMNAPITRANSFORMER_H
#include "napi/native_api.h"
#include <map>
#include <string>
namespace rcim {

class NativeObject;

namespace trans {
// 基本数据类型转换 ******************************************************************
std::string stringFromValue(napi_env env, napi_value value);
napi_value stringToValue(napi_env env, std::string str);
void setPropertyString(napi_env env, napi_value obj, std::string k, std::string v);
std::string getPropertyString(napi_env env, napi_value obj, std::string k);
napi_value getPropertyObject(napi_env env, napi_value obj, std::string k);

// const char *charFromStringByMallocSafety(std::string str);
std::string charToStringFromSafety(const char *char_ptr);

int32_t int32FromValue(napi_env env, napi_value value);
napi_value int32ToValue(napi_env env, int32_t num);
void setPropertyInt32(napi_env env, napi_value obj, std::string k, int32_t v);
int32_t getPropertyInt32(napi_env env, napi_value obj, std::string k);

int64_t int64FromValue(napi_env env, napi_value value);
napi_value int64ToValue(napi_env env, int64_t num);
void setPropertyInt64(napi_env env, napi_value obj, std::string k, int64_t v);
int64_t getPropertyInt64(napi_env env, napi_value obj, std::string k);

bool boolFromValue(napi_env env, napi_value value);
napi_value boolToValue(napi_env env, bool num);
void setPropertyBool(napi_env env, napi_value obj, std::string k, bool v);
bool getPropertyBool(napi_env env, napi_value obj, std::string k);

void setPropertyObject(napi_env env, napi_value obj, std::string k, NativeObject *nativeObj);

// 获取数组长度，array_value 为数组时返回其长度
uint32_t lengthFromValue(napi_env env, napi_value array_value);

// 将 NativeKV 数组改为 Map
void mapFromValueByNativeKVArray(napi_env env, napi_value array_value, uint32_t len,
                                 std::map<std::string, std::string> &map);
} // namespace trans
} // namespace rcim

#endif // RONGIMLIBTESTDEMO_RCIMNAPITRANSFORMER_H
